package com.atguigu.spzx.cloud.order.controller;


import com.atguigu.spzx.cloud.feign.api.UserFeignClient;
import com.atguigu.spzx.cloud.model.entity.Order;
import com.atguigu.spzx.cloud.model.entity.User;
import com.atguigu.spzx.cloud.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping(value = "/api/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService ;

    @Autowired
    private RestTemplate restTemplate ;

    @Autowired
    private UserFeignClient userFeignClient ;

    @GetMapping(value = "/findOrderByOrderId/{orderId}")
    public Order findOrderByOrderId(@PathVariable("orderId") Long orderId, @RequestHeader(name = "Truth")String header) {
        Order order = orderService.findOrderByOrderId(orderId);
        Long userId = order.getUserId();
//        User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + userId, User.class);
//        log.info("UserController...findUserByUserId方法执行了... ,header: {} " , header);
        User user = userFeignClient.queryById(userId);
        order.setUser(user);
        return order;
    }

}